// xc_lshop/savemoney/stroll/hotprolist.js
var smapidata = require('../model/smapi_data.js')

Page({
  mixins: [require('../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {

  },

  xcloaddata: function (options, config) {
    
    var that=this;
    var update = {};
    if (config && config.jtklmapi ) {
      if(config.jtklmapi.status==1){
        update['strollconfig'] = config.jtklmapi.stroll
        var windowWidth="";
      
        wx.getSystemInfo({
          success: (result) => {
            windowWidth=result['windowWidth']
          },
        })
        var width=(windowWidth - 20) * 0.485 
        width=width.toFixed(2)
        this.setData({
          itemwidth:width
        })
        update['source']=options.source
        update['type']=options.type

        this.setData(update)
        this.getpagelist(this,1)
        // this.getnavdata()
      }else{
        this.error("功能已关闭",true)
      }
    }else{
      this.error("省钱未配制",true)
    }
    
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere={};
        strwhere['source']=this.data.source
        strwhere['type']=this.data.type
      }
    }
    smapidata.hotoffset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
         if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"]['data'];
        } else {
          if (result["obj"]["modellist"]['data'].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]['data']);
          }
        }
      }     
      wx.stopPullDownRefresh();
   
      that.setData(updatemdoel);
    }, function () {
  
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
     this.getpagelist(this,-1)
  },

  
})